<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div class="box">
        <p class="p1"></p>
        <img class="p2">
    </div>
    <script>
        // let xhr=new XMLHttpRequest();
        // xhr.open("get","./navlist.json");
        // xhr.send();
        // xhr.onreadystatechange=function(){
        //     if(xhr.readyState==4 && xhr.status==200){
        //         let obj=JSON.parse(xhr.responseText);
        //         document.querySelector(".p1").textContent=obj.data[0].name;
        //         document.querySelector(".p2").src=obj.data[0].img;
        //         console.log(obj);
        //     }
        // }

        function get(url,callback){
            let xhr=new XMLHttpRequest();
            xhr.open("get",url);
            xhr.send();
            xhr.onreadystatechange=function(){
                if(xhr.readyState==4 && xhr.status==200){
                    let obj=JSON.parse(xhr.responseText);
                    callback(obj);
                }
            }      
        }
        let obj=get("./navlist.json",function(res){
            let data=res.data;
            let html="";
            data.forEach(function(item){
                html+=`
                    <div class="box">
                        <p class="p1">${item.name}</p>
                        <img class="p2" src="${item.img}">
                    </div>
                `;
            })
            document.querySelector("body").innerHTML=html;
        })

        let obj1=get("./goods_list.json",function(res){
            let data=res.data;
            let html="";
            data.forEach(function(item){
                html+=`
                    <div class="box">
                        <p class="p1">${item.title}</p>
                        <p class="p1">${item.content}</p>
                        <img class="p2" src="${item.img}">
                    </div>
                `;
            })
            document.querySelector("body").innerHTML+=html;
        })
    </script>
</body>
</html>